This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Cmd+Shift+Enter.
install.packages("data.table")
library(data.table)
install.packages("plotly")
library(plotly)
install.packages("stringr")
library(stringr)
install.packages("stringr")
library(stringr)
install.packages("plyr")
library(plyr)
Crawford
library(data.table)
library(plotly)
library(stringr)
library("moments")
#pre <- fread("CYSMN_Pre Survey_MODIFIED.csv")
post <- fread("CYSMN_Post Survey_MODIFIED.csv")
scentB <- post[ which(str_detect(post$Q19, "B")),]
scentA <- post[ which(str_detect(post$Q19, "A")),]
# Begin Plots
Questions <- c("Q1", "Q2", "Q3")
rosemary <- c(mean(scentA$Q1), mean(scentA$Q2), mean(scentA$Q3))
lavender <- c(mean(scentB$Q1), mean(scentB$Q2), mean(scentB$Q3))
data <- data.frame(Questions, rosemary, lavender)
# Calculate standard deviations
lavender_sd <- rbind(scentA$Q1, scentA$Q2, scentA$Q3)
rosemary_sd <- rbind(scentB$Q1, scentB$Q2, scentB$Q3)
lavender_sd_final <- apply(lavender_sd, 1, function(x) sd(x))
rosemary_sd_final <- apply(rosemary_sd, 1, function(x) sd(x))
fig <- plot_ly(data, x = ~Questions, y = ~rosemary, type = 'bar', name = 'Rosemary', error_y = ~list(array = rosemary_sd_final, color = '#000000'))
fig <- fig %>% add_trace(y = ~lavender, name = 'Lavender', error_y = ~list(array = lavender_sd_final, color = '#000000'))
fig <- fig %>% layout(yaxis = list(title = 'Rating'), barmode = 'group')
fig
#Test Q1
wilcox.test(scentA$Q1, scentB$Q1, paired = FALSE)
cannot compute exact p-value with ties
Wilcoxon rank sum test with continuity correction
data: scentA$Q1 and scentB$Q1
W = 15.5, p-value = 0.6733
alternative hypothesis: true location shift is not equal to 0
#Test Q2
wilcox.test(scentA$Q2, scentB$Q2, paired = FALSE)
cannot compute exact p-value with ties
Wilcoxon rank sum test with continuity correction
data: scentA$Q2 and scentB$Q2
W = 15, p-value = 0.5948
alternative hypothesis: true location shift is not equal to 0
#Test Q3
wilcox.test(scentA$Q3, scentB$Q3, paired = FALSE)
cannot compute exact p-value with ties
Wilcoxon rank sum test with continuity correction
data: scentA$Q3 and scentB$Q3
W = 13, p-value = 0.4372
alternative hypothesis: true location shift is not equal to 0
#Test Q4
wilcox.test(scentA$Q4, scentB$Q4, paired = FALSE)
cannot compute exact p-value with ties
Wilcoxon rank sum test with continuity correction
data: scentA$Q4 and scentB$Q4
W = 9, p-value = 0.143
alternative hypothesis: true location shift is not equal to 0
#Test Q5
wilcox.test(scentA$Q5, scentB$Q5, paired = FALSE)
cannot compute exact p-value with ties
Wilcoxon rank sum test with continuity correction
data: scentA$Q5 and scentB$Q5
W = 10.5, p-value = 0.2259
alternative hypothesis: true location shift is not equal to 0
#Test Q6
wilcox.test(scentA$Q6, scentB$Q6, paired = FALSE)
cannot compute exact p-value with ties
Wilcoxon rank sum test with continuity correction
data: scentA$Q6 and scentB$Q6
W = 19.5, p-value = 0.8653
alternative hypothesis: true location shift is not equal to 0
#Test Q7
wilcox.test(scentA$Q7, scentB$Q7, paired = FALSE)
cannot compute exact p-value with ties
Wilcoxon rank sum test with continuity correction
data: scentA$Q7 and scentB$Q7
W = 19, p-value = 0.9313
alternative hypothesis: true location shift is not equal to 0
#Test Q7
wilcox.test(scentA$Q7, scentB$Q7, paired = FALSE)
cannot compute exact p-value with ties
Wilcoxon rank sum test with continuity correction
data: scentA$Q7 and scentB$Q7
W = 19, p-value = 0.9313
alternative hypothesis: true location shift is not equal to 0
#Test Q8
wilcox.test(scentA$Q8, scentB$Q8, paired = FALSE)
cannot compute exact p-value with ties
Wilcoxon rank sum test with continuity correction
data: scentA$Q8 and scentB$Q8
W = 27, p-value = 0.1597
alternative hypothesis: true location shift is not equal to 0
#Test Q9
wilcox.test(scentA$Q9, scentB$Q9, paired = FALSE)
cannot compute exact p-value with ties
Wilcoxon rank sum test with continuity correction
data: scentA$Q9 and scentB$Q9
W = 12, p-value = 0.2824
alternative hypothesis: true location shift is not equal to 0
#Test Q10
wilcox.test(scentA$Q10, scentB$Q10, paired = FALSE)
cannot compute exact p-value with ties
Wilcoxon rank sum test with continuity correction
data: scentA$Q10 and scentB$Q10
W = 17, p-value = 0.9312
alternative hypothesis: true location shift is not equal to 0
#Test Q11
wilcox.test(scentA$Q11, scentB$Q11, paired = FALSE)
cannot compute exact p-value with ties
Wilcoxon rank sum test with continuity correction
data: scentA$Q11 and scentB$Q11
W = 20, p-value = 0.8055
alternative hypothesis: true location shift is not equal to 0
#Test Q12
wilcox.test(scentA$Q12, scentB$Q12, paired = FALSE)
cannot compute exact p-value with ties
Wilcoxon rank sum test with continuity correction
data: scentA$Q12 and scentB$Q12
W = 14.5, p-value = 0.6229
alternative hypothesis: true location shift is not equal to 0
Load Data
rr
data <- fread(_Post Survey_MODIFIED.csv)
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Cmd+Option+I. scriptive Statistics
rr
#Get Type A Questions
COLUMN STATEMENTS
Q1A <- c(scentA\(Q1) Q13A <- c(scentA\)Q13) Q14A <- c(scentA\(Q14) Q2A <- c(scentA\)Q2) Q3A <- c(scentA\(Q3) Q4A <- c(scentA\)Q4) Q5A <- c(scentA\(Q5) Q6A <- c(scentA\)Q6) Q7A <- c(scentA\(Q7) Q8A <- c(scentA\)Q8) Q9A <- c(scentA\(Q9) Q10A <- c(scentA\)Q10) Q11A <- c(scentA\(Q11) Q12A <- c(scentA\)Q12)
AVERAGE STATEMENTS
avgQ1A <- mean(Q1A) avgQ13A <- mean(Q13A) avgQ14A <- mean(Q14A) avgQ2A <- mean(Q2A) avgQ3A <- mean(Q3A) avgQ4A <- mean(Q4A) avgQ5A <- mean(Q5A) avgQ6A <- mean(Q6A) avgQ7A <- mean(Q7A) avgQ8A <- mean(Q8A) avgQ9A <- mean(Q9A) avgQ10A <- mean(Q10A) avgQ11A <- mean(Q11A) avgQ12A <- mean(Q12A)
PRINT STATEMENTS
stringQ1A <- 1 for Type A average:
print(paste(stringQ1A, avgQ1A))
[1] \Question 1 for Type A average: 5.33333333333333\
rr print(\)
[1] \\
rr stringQ13A <- 2 for Type A average:
print(paste(stringQ13A, avgQ13A))
[1] \Question 2 for Type A average: 7\
rr print(\)
[1] \\
rr stringQ14A <- 3 for Type A average:
print(paste(stringQ14A, avgQ14A))
[1] \Question 3 for Type A average: 3.5\
rr print(\)
[1] \\
rr stringQ2A <- 4 for Type A average:
print(paste(stringQ2A, avgQ2A))
[1] \Question 4 for Type A average: 5.16666666666667\
rr print(\)
[1] \\
rr stringQ3A <- 5 for Type A average:
print(paste(stringQ3A, avgQ3A))
[1] \Question 5 for Type A average: 5.33333333333333\
rr print(\)
[1] \\
rr stringQ4A <- 6 for Type A average:
print(paste(stringQ4A, avgQ4A))
[1] \Question 6 for Type A average: 4.66666666666667\
rr print(\)
[1] \\
rr stringQ5A <- 7 for Type A average:
print(paste(stringQ5A, avgQ5A))
[1] \Question 7 for Type A average: 1.83333333333333\
rr print(\)
[1] \\
rr stringQ6A <- 8 for Type A average:
print(paste(stringQ6A, avgQ6A))
[1] \Question 8 for Type A average: 6.16666666666667\
rr print(\)
[1] \\
rr stringQ7A <- 9 for Type A average:
print(paste(stringQ7A, avgQ7A))
[1] \Question 9 for Type A average: 5.5\
rr print(\)
[1] \\
rr stringQ8A <- 10 for Type A average:
print(paste(stringQ8A, avgQ8A))
[1] \Question 10 for Type A average: 3.83333333333333\
rr print(\)
[1] \\
rr stringQ9A <- 11 for Type A average:
print(paste(stringQ9A, avgQ9A))
[1] \Question 11 for Type A average: 1.16666666666667\
rr print(\)
[1] \\
rr stringQ10A <- 12 for Type A average:
print(paste(stringQ10A, avgQ10A))
[1] \Question 12 for Type A average: 5.83333333333333\
rr print(\)
[1] \\
rr stringQ11A <- 13 for Type A average:
print(paste(stringQ11A, avgQ11A))
[1] \Question 13 for Type A average: 4\
rr print(\)
[1] \\
rr stringQ12A <- 14 for Type A average:
print(paste(stringQ12A, avgQ12A))
[1] \Question 14 for Type A average: 4.16666666666667\
rr print(\)
[1] \\
rr
#Get Type B Questions
COLUMN STATEMENTS
Q1B <- c(scentB\(Q1) Q13B <- c(scentB\)Q13) Q14B <- c(scentB\(Q14) Q2B <- c(scentB\)Q2) Q3B <- c(scentB\(Q3) Q4B <- c(scentB\)Q4) Q5B <- c(scentB\(Q5) Q6B <- c(scentB\)Q6) Q7B <- c(scentB\(Q7) Q8B <- c(scentB\)Q8) Q9B <- c(scentB\(Q9) Q10B <- c(scentB\)Q10) Q11B <- c(scentB\(Q11) Q12B <- c(scentB\)Q12)
AVERAGE STATEMENTS
avgQ1B <- mean(Q1B) avgQ13B <- mean(Q13B) avgQ14B <- mean(Q14B) avgQ2B <- mean(Q2B) avgQ3B <- mean(Q3B) avgQ4B <- mean(Q4B) avgQ5B <- mean(Q5B) avgQ6B <- mean(Q6B) avgQ7B <- mean(Q7B) avgQ8B <- mean(Q8B) avgQ9B <- mean(Q9B) avgQ10B <- mean(Q10B) avgQ11B <- mean(Q11B) avgQ12B <- mean(Q12B)
PRINT STATEMENTS
stringQ1B <- 1 for Type B average:
print(paste(stringQ1B, avgQ1B))
[1] \Question 1 for Type B average: 6.16666666666667\
rr print(\)
[1] \\
rr stringQ13B <- 2 for Type B average:
print(paste(stringQ13B, avgQ13B))
[1] \Question 2 for Type B average: 6.83333333333333\
rr print(\)
[1] \\
rr stringQ14B <- 3 for Type B average:
print(paste(stringQ14B, avgQ14B))
[1] \Question 3 for Type B average: 2.33333333333333\
rr print(\)
[1] \\
rr stringQ2B <- 4 for Type B average:
print(paste(stringQ2B, avgQ2B))
[1] \Question 4 for Type B average: 5.33333333333333\
rr print(\)
[1] \\
rr stringQ3B <- 5 for Type B average:
print(paste(stringQ3B, avgQ3B))
[1] \Question 5 for Type B average: 6.16666666666667\
rr print(\)
[1] \\
rr stringQ4B <- 6 for Type B average:
print(paste(stringQ4B, avgQ4B))
[1] \Question 6 for Type B average: 5.83333333333333\
rr print(\)
[1] \\
rr stringQ5B <- 7 for Type B average:
print(paste(stringQ5B, avgQ5B))
[1] \Question 7 for Type B average: 2.33333333333333\
rr print(\)
[1] \\
rr stringQ6B <- 8 for Type B average:
print(paste(stringQ6B, avgQ6B))
[1] \Question 8 for Type B average: 5.66666666666667\
rr print(\)
[1] \\
rr stringQ7B <- 9 for Type B average:
print(paste(stringQ7B, avgQ7B))
[1] \Question 9 for Type B average: 5.16666666666667\
rr print(\)
[1] \\
rr stringQ8B <- 10 for Type B average:
print(paste(stringQ8B, avgQ8B))
[1] \Question 10 for Type B average: 2.66666666666667\
rr print(\)
[1] \\
rr stringQ9B <- 11 for Type B average:
print(paste(stringQ9B, avgQ9B))
[1] \Question 11 for Type B average: 1.5\
rr print(\)
[1] \\
rr stringQ10B <- 12 for Type B average:
print(paste(stringQ10B, avgQ10B))
[1] \Question 12 for Type B average: 6\
rr print(\)
[1] \\
rr stringQ11B <- 13 for Type B average:
print(paste(stringQ11B, avgQ11B))
[1] \Question 13 for Type B average: 3.66666666666667\
rr print(\)
[1] \\
rr stringQ12B <- 14 for Type B average:
print(paste(stringQ12B, avgQ12B))
[1] \Question 14 for Type B average: 4.66666666666667\
rr print(\)
[1] \\
rr
Wilcox Testing for Type A
testQ1 <- t.test(Q1B, Q1A) print(testQ1)
Welch Two Sample t-test
data: Q1B and Q1A
t = 0.92848, df = 5.3567, p-value = 0.3931
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-1.428383 3.095050
sample estimates:
mean of x mean of y
6.166667 5.333333
rr
New data frame for Type A
new_df_TA <- data.frame(Q1A, Q13A, Q14A, Q2A, Q3A, Q4A, Q5A, Q6A, Q7A, Q8A, Q9A, Q10A, Q11A, Q12A)
Skewed Values for Type A
skew_Q1A <- skewness(new_df_TA\(Q1A) skew_Q13A <- skewness(new_df_TA\)Q13A) skew_Q14A <- skewness(new_df_TA\(Q14A) skew_Q2A <- skewness(new_df_TA\)Q2A) skew_Q3A <- skewness(new_df_TA\(Q3A) skew_Q4A <- skewness(new_df_TA\)Q4A) skew_Q5A <- skewness(new_df_TA\(Q5A) skew_Q6A <- skewness(new_df_TA\)Q6A) skew_Q7A <- skewness(new_df_TA\(Q7A) skew_Q8A <- skewness(new_df_TA\)Q8A) skew_Q9A <- skewness(new_df_TA\(Q9A) skew_Q10A <- skewness(new_df_TA\)Q10A) skew_Q11A <- skewness(new_df_TA\(Q11A) skew_Q12A <- skewness(new_df_TA\)Q12A)
rr
library(datasets) data(iris) library(plotly) # https://plotly.com/r/line-and-scatter/